package com.zhang.publicproject.common.utils;

import android.text.TextUtils;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by Administrator on 2017/8/31.
 */

public class SignEnctypyUtils {


        public void getUrl(Map<String,Object> map,String keyWords){
            Map<String, String> m5dMap = new HashMap<>();
            long time = System.currentTimeMillis() / 1000;


            // String sign = MD5Utils.getSortUrlParams("/login/login/" + name + "?", m5dMap);
            /**
             * 创建请求的参数body
             */
            Map<String, String> infoMap = new HashMap();
            /**
             * 遍历key
             */
            if (null != map) {
                for (Map.Entry<String, Object> entry : map.entrySet()) {

                    System.out.println("Key = " + entry.getKey() + ", Value = " + entry.getValue());

                    if (!TextUtils.isEmpty(entry.getValue().toString())) {
                        m5dMap.put(entry.getKey(), entry.getValue().toString());
                    }
                    //判断参数是否是中文
                    if (StringUtils.isChinese(entry.getValue().toString())) {
                        try {

                            infoMap.put(entry.getKey(), URLEncoder.encode(entry.getValue().toString(), "UTF-8"));
                        } catch (UnsupportedEncodingException e) {
                            e.printStackTrace();
                        }
                    } else {
                        infoMap.put(entry.getKey(), entry.getValue().toString());
                    }


                }
                m5dMap.put("timestamp", time + "");
                String sign = MD5Utils.getSortUrlParams(keyWords, m5dMap);
                infoMap.put("timestamp", time + "");
                infoMap.put("sign", sign);
            }
           // return infoMap;
        }



}
